﻿#region

using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using LocalNugetUpdate.Model;
using LocalNugetUpdate.Model.NupkgModelJsonTypes;

#endregion

namespace LocalNugetUpdate.BAL.Mehtod
{
    public class ConfigDataShowClass
    {
        public static BindingList<DataShowModel> ConvertDataShowModels(List<Metadata> metas)
        {
            List<DataShowModel> datas = new List<DataShowModel>();
            foreach (Metadata meta in metas)
            {
                var _meta = datas.FirstOrDefault(d => d.Id == meta.Id);
                if (_meta == null)
                {
                    DataShowModel dsm = new DataShowModel();
                    dsm.Id = meta.Id;
                    dsm.Versions = new List<string>();
                    dsm.Versions.Add(meta.Version);
                    datas.Add(dsm);
                }
                else
                {
                    _meta.Versions.Add(meta.Version);
                }
            }

            return new BindingList<DataShowModel>(datas);
        }
    }
}